import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_methods.dart';

class XinDongLiaoTianInputController extends GetxController {
  static XinDongLiaoTianInputController get to => Get.find();
  final TextEditingController inputController = TextEditingController();

  RxBool _upSpring = false.obs;
  RxBool _miniGames = false.obs;
  RxBool _newFunction = false.obs;
  bool keyboard = false;
  bool get upSpring => _upSpring.value;

  set upSpring(bool value) {
    _upSpring.value = value;
  }

  bool get miniGames => _miniGames.value;

  set miniGames(bool value) {
    _miniGames.value = value;
  }

  bool get newFunction => _newFunction.value;

  set newFunction(bool value) {
    _newFunction.value = value;
  }

  XinDongLiaoTianInputController() {
    inputController.addListener(() {
      update();
    });
  }

  // 将表情发送到输入框
  void onEmojiSelected(String emoji) {
    inputController
      ..text += emoji
      ..selection = TextSelection.fromPosition(TextPosition(offset: inputController.text.length));
  }

  // 是否打开表情框
  bool onUpSpring() {
    upSpring = !upSpring;
    update();
    return upSpring;
  }

  //关闭表情
  void close() {
    if (upSpring == true) {
      upSpring = false;
      update();
    }
  }

  // 是否打开小游戏
  bool onMiniGames() {
    miniGames = !miniGames;
    update();
    return miniGames;
  }

  void upKeyboard(bool keyboard) {
    if (this.keyboard == keyboard) {
      return;
    }
    this.keyboard = keyboard;
    update();
  }

  // 关闭小游戏
  void closeMiniGames() {
    if (miniGames == true) {
      miniGames = false;
      update();
    }
  }

  void closeAll() {
    close();
    closeMiniGames();
    FocusScope.of(currentContext()).requestFocus(FocusNode());
  }

}
